var data = [{
	title: "首页",
	titleprame: "menushopping",
	id: "adminNavTabs_menushopping",
	url: "http://www.yiqun1688.com",
	icon: "el-icon-menu",
	index: "1",
	names: [{
		name: "",
		icon: "",
		index: "1-1",
		nameitem: [{
			detail: "",
			dataurl: "",
			icon: "",
			index: "1-11",
			dataprame: ""
		}]
	}]
}, {
	title: "合作伙伴",
	titleprame: "menushopping",
	id: "adminNavTabs_hzhb",
	url: "/CooperativePartner",
	icon: "el-icon-minus",
	index: "2",
	names: [{
		name: "",
		icon: "",
		index: "2-1",
		nameitem: [{
			detail: "",
			dataurl: "",
			icon: "",
			index: "2-11",
			dataprame: ""
		}]
	}]
}, {
	title: "行业标准",
	titleprame: "menushopping",
	id: "adminNavTabs_hybz",
	url:'/IndustryStandard',
	icon: "el-icon-star-off",
	index: "3",
	names: [{
		name: "",
		icon: "",
		index: "3-1",
		nameitem: [{
			detail: "",
			icon: "",
			dataurl: "",
			index: "3-11",
			dataprame: ""
		}]
	}]
}, {
	title: "设置",
	titleprame: "menuplatform",
	id: "adminNavTabs_menuplatform",
	icon: "el-icon-setting",
	url: "set",
	index: "4",
	names: [{
		name: "设置",
		index: "4-1",
		icon: "el-icon-setting",
		nameitem: [{
			detail: "基础设置",
			icon: "el-icon-setting",
			dataurl: "http://www.sina.com.cn",
			index: "4-11",
			dataprame: "menuplatform|01_shop_config"
		}, {
			detail: "SEO设置",
			icon: "el-icon-information",
			dataurl: "http://www.baidu.com",
			index: "4-12",
			dataprame: "menuplatform|021_reg_fields"
		}]
	}, {
		name: "广告",
		index: "4-2",
		icon: "el-icon-information",
		nameitem: [{
			detail: "合作钢厂",
			icon: "el-icon-information",
			dataurl: "http://aosensteel.chinatsi.com/",
			index: "4-21",
			dataprame: "menuplatform|ad_list"
		}, {
			detail: "合作客户",
			icon: "el-icon-information",
			dataurl: "http://www.chunxinggroup.cn/",
			index: "4-22",
			dataprame: "menuplatform|ad_position"
		}]
	}]
}, {
	title: "文章",
	titleprame: "menushopping",
	id: "adminNavTabs_menushopping",
	icon: "el-icon-document",
	url: "actric",
	index: "5",
	names: [{
		name: "资讯",
		icon: "el-icon-document",
		index: "5-1",
		nameitem: [{
			detail: "价格行情",
			icon: "el-icon-document",
			dataurl: "http://nc.mofcom.gov.cn/channel/gxdj/jghq/",
			index: "5-11",
			dataprame: "menushopping|01_goods_list"
		}, {
			detail: "价格动态",
			icon: "el-icon-document",
			dataurl: "http://www.zh818.com/",
			index: "5-12",
			dataprame: "menushopping|05_comment_manage"
		}]
	}]
}, {
	title: "日志",
	titleprame: "ectouch",
	id: "adminNavTabs_ectouch",
	icon: "el-icon-date",
	url: "rizhi",
	index: "6",
	names: [{
		name: "日志",
		icon: "el-icon-date",
		index: "6-1",
		nameitem: [{
			detail: "日志查看",
			icon: "el-icon-date",
			dataurl: "http://www.zh818.com/",
			index: "6-11",
			dataprame: "ectouch|01_oauth_admin"
		}]
	}]
}];
$(function() {
	loadUrl("http://www.yiqun1688.com");
	new Vue({
		el: '#admincj_nav',
		data: {
			datas: data
		},
		methods: {
			handleOpen: function(key, keyPath) {
				console.log(key, keyPath);
			},
			handleClose: function(key, keyPath) {
				console.log(key, keyPath);
			},
			OpenMyUrl: function(key, keyPath) {
				loadUrl(key);
			}
		}
	});
	
	function InitindexNav() {
		$(".item").eq(0).addClass("current");
		//	LoadIndexUrl(); //加载行业标准，合作伙伴
	}

	//logo点击跳转到首页
	$(".admin-logo a").on("click", function() {
		var param = $(this).data('param');
		$(".admin-main").addClass("start_home");
		$(".admincj_nav").show();
		$("#adminNavTabs_menuplatform").remove();
		InitindexNav();

		$(".module-menu").find("li").removeClass("active");
		openItem(param);
	});

	//顶部管理员信息展开
	function adminSetup() {
		var hoverTimer, outTimer;
		$('#admin-manager-btn,.manager-menu,.admincp-map').mouseenter(function() {
			clearTimeout(outTimer);
			hoverTimer = setTimeout(function() {
				$('.manager-menu').show();
				$('#admin-manager-btn').removeClass().addClass("arrow-close");
			}, 200);
		});

		$('#admin-manager-btn,.manager-menu,.admincp-map').mouseleave(function() {
			clearTimeout(hoverTimer);
			outTimer = setTimeout(function() {
				$('.manager-menu').hide();
				$('#admin-manager-btn').removeClass().addClass("arrow");
			}, 100);
		});
	}
	adminSetup();

	function loadEach() {
		$('.admincj_nav').find('div[id^="adminNavTabs_"]').each(function() {
			var $this = $(this);
			$this.find('.item > .tit > a').each(function(i) {
				$(this).parent().next().css('top', (-68) * i + 'px');
				$(this).click(function() {
					var url = '';
					$this.find('.sub-menu').hide();
					$this.find('.item').removeClass('current');
					$(this).parents('.item:first').addClass('current');
					$(this).parent().next().find('a:first').click();
					url = $(this).parent().next().find('a:first').data('url');
					loadUrl(url);
				});
			});
		});
	}
	//loadEach(); //tit左侧菜单栏一层点击事件
	//加载行业标准，合作伙伴
	function LoadIndexUrl() {
		$(".admincj_nav .item").each(function() {
			$(this).click(function() {
				$(".item").eq(0).removeClass("current");
				$(this).parent().addClass("current").siblings().removeClass("current");
				var url = $(this).data("url");
				loadUrl(url);
			})
		})
	}
	LoadIndexUrl();
	//顶部导航栏菜单切换
	$(".operate").each(function() {
		//顶部布局换色设置
		var bgColorSelectorColors = [{
			c: '#324057',
			cName: ''
		}, {
			c: '#981767',
			cName: ''
		}, {
			c: '#AD116B',
			cName: ''
		}, {
			c: '#B61944',
			cName: ''
		}, {
			c: '#AA1815',
			cName: ''
		}, {
			c: '#C4182D',
			cName: ''
		}, {
			c: '#D74641',
			cName: ''
		}, {
			c: '#ED6E4D',
			cName: ''
		}, {
			c: '#D78A67',
			cName: ''
		}, {
			c: '#F5A675',
			cName: ''
		}, {
			c: '#F8C888',
			cName: ''
		}, {
			c: '#F9D39B',
			cName: ''
		}, {
			c: '#F8DB87',
			cName: ''
		}, {
			c: '#FFD839',
			cName: ''
		}, {
			c: '#F9D12C',
			cName: ''
		}, {
			c: '#FABB3D',
			cName: ''
		}, {
			c: '#F8CB3C',
			cName: ''
		}, {
			c: '#F4E47E',
			cName: ''
		}, {
			c: '#F4ED87',
			cName: ''
		}, {
			c: '#DFE05E',
			cName: ''
		}, {
			c: '#CDCA5B',
			cName: ''
		}, {
			c: '#A8C03D',
			cName: ''
		}, {
			c: '#73A833',
			cName: ''
		}, {
			c: '#468E33',
			cName: ''
		}, {
			c: '#5CB147',
			cName: ''
		}, {
			c: '#6BB979',
			cName: ''
		}, {
			c: '#8EC89C',
			cName: ''
		}, {
			c: '#9AD0B9',
			cName: ''
		}, {
			c: '#97D3E3',
			cName: ''
		}, {
			c: '#7CCCEE',
			cName: ''
		}, {
			c: '#5AC3EC',
			cName: ''
		}, {
			c: '#16B8D8',
			cName: ''
		}, {
			c: '#49B4D6',
			cName: ''
		}, {
			c: '#6DB4E4',
			cName: ''
		}, {
			c: '#8DC2EA',
			cName: ''
		}, {
			c: '#BDB8DC',
			cName: ''
		}, {
			c: '#8381BD',
			cName: ''
		}, {
			c: '#7B6FB0',
			cName: ''
		}, {
			c: '#AA86BC',
			cName: ''
		}, {
			c: '#AA7AB3',
			cName: ''
		}, {
			c: '#935EA2',
			cName: ''
		}, {
			c: '#9D559C',
			cName: ''
		}, {
			c: '#C95C9D',
			cName: ''
		}, {
			c: '#DC75AB',
			cName: ''
		}, {
			c: '#EE7DAE',
			cName: ''
		}, {
			c: '#E6A5CA',
			cName: ''
		}, {
			c: '#EA94BE',
			cName: ''
		}, {
			c: '#D63F7D',
			cName: ''
		}, {
			c: '#C1374A',
			cName: ''
		}, {
			c: '#AB3255',
			cName: ''
		}, {
			c: '#A51263',
			cName: ''
		}, {
			c: '#7F285D',
			cName: ''
		}, {
			c: '#1e89e0',
			cName: ''
		}, {
			c: '#475669',
			cName: ''
		}];
		$("#trace_show").click(function() {
			$("div.bgSelector").toggle(300, function() {
				if($(this).html() == '') {
					$(this).sColor({
						colors: bgColorSelectorColors, // 必填，所有颜色 c:色号（必填） cName:颜色名称（可空）
						colorsWidth: '50px', // 必填，颜色的高度
						colorsHeight: '31px', // 必填，颜色的高度
						curTop: '0', // 可选，颜色选择对象高偏移，默认0
						curImg: 'images/cur.png', //必填，颜色选择对象图片路径
						form: 'drag', // 可选，切换方式，drag或click，默认drag
						keyEvent: true, // 可选，开启键盘控制，默认true
						prevColor: true, // 可选，开启切换页面后背景色是上一页面所选背景色，如不填则换页后背景色是defaultItem，默认false
						defaultItem: ($.cookie('bgColorSelectorPosition') != null) ? $.cookie('bgColorSelectorPosition') : 22 // 可选，第几个颜色的索引作为初始颜色，默认第1个颜色
					});
				}
			}); //切换显示
		});
		if($.cookie('bgColorSelectorPosition') != null) {
			$('body').css('background-color', bgColorSelectorColors[$.cookie('bgColorSelectorPosition')].c);
		} else {
			$('body').css('background-color', bgColorSelectorColors[0].c);
		}

		//上传管理员头像
		$("#_pic").change(function() {
			var actionUrl = "index.php?act=upload_store_img";
			$("#fileForm").ajaxSubmit({
				type: "POST",
				dataType: "json",
				url: actionUrl,
				data: {
					"action": "TemporaryImage"
				},
				success: function(data) {
					if(data.error == "0") {
						//					alert(data.massege);
					} else if(data.error == "1") {
						$(".avatar img").attr("src", data.content);
					}
				},
				async: true
			});
		});
		//没有cookie默认选择起始页
		if($.cookie('dscActionParam') == null) {
			$('.admin-logo').find('a').click();
		} else {
			openItem($.cookie('dscActionParam'));
		}
		/*  @author-bylu 添加快捷菜单 start  */
		$('.admincp-map-nav li').click(function() {
			var i = $(this).index();
			$(this).addClass('selected');
			$(this).siblings().removeClass('selected');
			$('.admincp-map-div').eq(i).show();
			$('.admincp-map-div').eq(i).siblings('.admincp-map-div').hide();
		});

		$('.admincp-map-div dd i').click(function() {
			var auth_name = $(this).prev('a').text();
			var auth_href = $(this).prev('a').attr('href');
			if(!$(this).parent('dd').hasClass('selected')) {

				if($('.admincp-map-div dd.selected').length >= 10) {
					//				alert('最多只允许添加10个快捷菜单!');
					return false;
				}

				$(this).parent('dd').addClass('selected');
				$('.quick_link ul').append('<li class="tl"><a href="' + auth_href + '" data-url="' + auth_href + '" data-param="" target="workspace">' + auth_name + '</a></li>')

				$.post('index.php?act=auth_menu', {
					'type': 'add',
					'auth_name': auth_name,
					'auth_href': auth_href
				});

			} else {
				$(this).parent('dd').removeClass('selected');
				$('.quick_link ul li').each(function(k, v) {
					if(auth_name == $(v).text()) {
						$(v).remove();
					}
				});
				$.post('index.php?act=auth_menu', {
					'type': 'del',
					'auth_name': auth_name,
					'auth_href': auth_href
				});
			}
		});

		$('.add_nav,.sitemap').click(function() {
			$('#allMenu').show();
		});

		//消息通知
		function message() {
			var hoverTimer, outTimer;
			$('.msg,#msg_Container').mouseenter(function() {
				clearTimeout(outTimer);
				hoverTimer = setTimeout(function() {
					$('#msg_Container').show();
				}, 200);
			});

			$('.msg,#msg_Container').mouseleave(function() {
				clearTimeout(hoverTimer);
				outTimer = setTimeout(function() {
					$('#msg_Container').hide();
				}, 100);
			});
		}
		message();
	});

});

function openItem(param) {
	//若cookie值不存在，则跳出iframe框架

	var $this = $('div[id^="adminNavTabs_"]').find('a[data-param="' + param + '"]');
	var url = $this.data('url');
	data_str = param.split('|');

	$this.parents('.admin-main').removeClass('start_home');

	if($this.parents(".admin-main").hasClass("fold")) {
		$this.parents('.sub-menu').hide();
	} else {
		$this.parents('.sub-menu').show();
	}
	$this.parents('.item').addClass('current').siblings().removeClass('current');
	$this.parents('li').addClass('curr').siblings().removeClass('curr');
	$this.parents('div[id^="adminNavTabs_"]').show().siblings().hide();
	$('li[data-param="' + data_str[0] + '"]').addClass('active');

	$.cookie('dscActionParam', data_str[0] + '|' + data_str[1], {
		expires: 1,
		path: '/'
	});

	if(param == 'index|main') {
		url = 'http://www.yiqun1688.com';
		loadUrl(url);
	}
}

function loadUrl(url) {

	$.cookie('dscUrl', url, {
		expires: 1,
		path: '/'
	});

	setTimeout(function() {
		$('.admin-main-right iframe[name="workspace"]').attr('src', url);
	}, 300);
}